/*
 * @Author: yangzonglong
 * @Date: 2021-05-11 15:20:20
 * @version: v1.0.0
 * @Descripttion: 
 * @LastEditors: yangzonglong
 * @LastEditTime: 2021-05-11 15:23:07
 * @Auditor: 
 */
import BaseRenderer from 'diagram-js/lib/draw/BaseRenderer';
import { append as svgAppend } from 'tiny-svg';
import { createLine } from 'diagram-js/lib/util/RenderUtil';
import { isAny } from 'bpmn-js/lib/features/modeling/util/ModelingUtil';

const HIGH_PRIORITY = 1500;

export default class CustomRenderer extends BaseRenderer {
    constructor(eventBus, bpmnRenderer, styles) {
        super(eventBus, HIGH_PRIORITY);

        this.bpmnRenderer = bpmnRenderer;
        this.styles = styles;
        console.log(this.getPath())
    }

    getPath() {}
    
    canRender(element) {
        return isAny(element, ['bpmn:Event', 'bpmn:SequenceFlow']);
    }

    drawCustomConnection(p, element) {
        let connectionStyle = this.styles.style(['no-fill'], {
            strokeWidth: 2,
            stroke: '#f00'
        });

        return svgAppend(p, createLine(element.waypoints, connectionStyle));
    };

    drawConnection(p, element) {
        const {
            type
        } = element;

        if (type === 'bpmn:SequenceFlow') {
            let path = this.getPath();
            if (path.includes(element.id))
                return this.drawCustomConnection(p, element);
            else super.drawConnection(p, element);
        }
    };
}

CustomRenderer.$inject = ['eventBus', 'bpmnRenderer', 'styles'];